﻿using BLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace L20241019.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MemberController : ControllerBase
    {
        public MemberController(MemberBll bll)
        {
            Bll = bll;
        }

        public MemberBll Bll { get; }

        /// <summary>
        /// 添加会员
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public IActionResult AddMember(Member m)
        {
            try
            {
                int res = Bll.AddMember(m);
                return Ok(new
                {
                    data = res
                });


            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 显示查询
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Phone"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public IActionResult ShowMember(string? Name, string? Phone )
        {
            try
            {
                List<Member> list = Bll.ShowMember(Name, Phone);

                return Ok(new
                {
                    data = list
                });

            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 逻辑单删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpDelete]
        public IActionResult DeleteMember(int id)
        {
            try
            {
                int res = Bll.DeleteMember(id);
                return Ok(new
                {

                    data = res
                });

            }
            catch (Exception)
            {

                throw;
            }

        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public IActionResult FanTian(int id)
        {
            try
            {
                var res = Bll.FanTian(id);
                return Ok(new { data = res });


            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="m">属性</param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public IActionResult UpdateMember(Member m)
        {
            try
            {
                int res = Bll.UpdateMember(m);
                return Ok(new
                {

                    data = res
                });

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
